
Page({
  data: {
    fileList: [],
  },
  // 文件上传完毕后会触发
  afterRead(e) {
    const { file } = e.detail;
    console.log(file);
    let that = this;
    wx.uploadFile({
      url: 'https://api-hmugo-web.itheima.net/api/private/v1/upload', // 上传接口
      filePath: file.url,
      name: 'file',
      header: {
        Authorization: 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOjUwMCwicmlkIjowLCJpYXQiOjE2NDYyNzYwMTgsImV4cCI6MTY0NjM2MjQxOH0.OJuEkOA_dR1Y7fRpmF1UHyEzksfhVMVWK4zUoF2BqY8',
      },
      formData: { user: 'test' },
      success: (res) => {
        console.log('上传完毕',res);
        const { fileList = [] } = this.data;
        fileList.push({ ...file, url: res.data });
        that.setData({ fileList });

        wx.showToast({
          title: '上传成功',
          icon: 'success',
          mask: true,
        });
      },
      fail: (fail) => {
        wx.showToast({
          title: '服务器上传失败',
          icon: 'success',
          mask: true,
        });
      },
    });
  },
  //文件删除操作
  delete(e) {
    const {index} = e.detail
    const { fileList } = this.data
    fileList.splice(index, 1)
    this.setData({
      fileList
    })
  },
  //提交
Submit(){
   console.log(this.data.fileList,);
  }
})